package fr.ants.view.renderer.pixel;

import java.awt.Color;
import java.awt.Graphics2D;

import fr.ants.model.Ant;
import fr.ants.view.panel.Canvas;
import fr.ants.view.renderer.AntRenderer;

/**
 * <p>Render an ant with pixels.</p> 
 *
 * @author Vianney DUPOY DE GUITARD
 */
public class AntPixelRenderer implements AntRenderer {

	/** Color mapper. */
	private ColorMap colorMap;

	/**
	 * Creates a new renderer.
	 * @param pColorMap : the color mapping used.
	 */
	public AntPixelRenderer(ColorMap pColorMap) {
		colorMap = pColorMap;
	}

	/** {@inheritDoc} */
	public void draw(int x, int y, Graphics2D g, Ant ant) {
		if (ant.isAlive()) {
			g.setColor(colorMap.getColor(ant.getNest()));
		} else {
			g.setColor(new Color(120, 120, 120));
		}
		g.fillOval(
				x * Canvas.NODE_SIZE + Canvas.NODE_SIZE / 4,
				y * Canvas.NODE_SIZE + Canvas.NODE_SIZE / 2,
				Canvas.NODE_SIZE / 2,
				Canvas.NODE_SIZE / 4);
	}
}